package com.allen.admin.service.server.service.impl;

import java.util.List;

import com.allen.admin.service.common.domain.AdminRole;
import com.allen.admin.service.common.service.AdminRoleService;
import com.allen.admin.service.server.manager.impl.AdminRoleManager;
import com.xxx.config.ModelResult;
import com.xxx.page.DataPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service("adminRoleService")
public class AdminRoleServiceImpl implements AdminRoleService {
	
	@Autowired
	private AdminRoleManager adminRoleManager;

	@Override
	public ModelResult<AdminRole> create(AdminRole obj) {
		ModelResult<AdminRole> resultModelResult = new ModelResult<>();
		AdminRole  role = adminRoleManager.insert(obj);
		resultModelResult.withModel(role);
		return resultModelResult;
	}

	@Override
	public ModelResult<AdminRole> update(AdminRole obj) {
		ModelResult<AdminRole> resultModelResult = new ModelResult<>();
		AdminRole role = adminRoleManager.update(obj);
		resultModelResult.withModel(role);
		return resultModelResult;
	}

	@Override
	public ModelResult<AdminRole> query(Integer id) {
		ModelResult<AdminRole> resultModelResult = new ModelResult<>();
		AdminRole role = adminRoleManager.select(id);
		resultModelResult.withModel(role);
		return resultModelResult;
	}
	
	@Override
	public ModelResult<AdminRole> queryByName(String name) {
		ModelResult<AdminRole> resultModelResult = new ModelResult<>();
		AdminRole role = adminRoleManager.selectByName(name);
		resultModelResult.withModel(role);
		return resultModelResult;
	}
	
	@Override
	public  ModelResult<AdminRole> queryByCode(String code) {
		ModelResult<AdminRole> resultModelResult = new ModelResult<>();
		AdminRole role = adminRoleManager.selectByCode(code);
		resultModelResult.withModel(role);
		return resultModelResult;
	}
	
	@Override
	public ModelResult<List<AdminRole>> query(List<Integer> ids) {
		ModelResult<List<AdminRole>> resultModelResult = new ModelResult<>();
		List<AdminRole> list = adminRoleManager.select(ids);
		resultModelResult.withModel(list);
		return resultModelResult;
	}
	
	@Override
	public ModelResult<List<AdminRole>> queryAllEnabled() {
		ModelResult<List<AdminRole>> resultModelResult = new ModelResult<>();
		List<AdminRole> list = adminRoleManager.selectAllEnabled();
		resultModelResult.withModel(list);
		return resultModelResult;
	}

	@Override
	public ModelResult<DataPage<AdminRole>> queryPage(DataPage<AdminRole> dataPage, AdminRole qObj) {
		ModelResult<DataPage<AdminRole>> resultModelResult = new ModelResult<>();
		dataPage = adminRoleManager.queryPage(dataPage, qObj);
		resultModelResult.withModel(dataPage);
		return resultModelResult;
	}

}
